<template>
  <div>
      <el-form  class="login-container" label-position="left"
               label-width="0px" v-loading="loading">
        <h3 class="login_title">登  录</h3>
        <el-form-item prop="account">
          <el-input type="text" v-model="loginForm.username"
                    auto-complete="off" placeholder="账号">
      		<i slot="prefix" class="el-input__icon el-icon-user"></i>
      		</el-input>
        </el-form-item>
        <el-form-item prop="checkPass">
          <el-input type="password" v-model="loginForm.password"
                    auto-complete="off" placeholder="密码">
      		<i slot="prefix" class="el-input__icon el-icon-lock"></i>
      		</el-input>
        </el-form-item>
        <el-form-item style="width: 100%">
          <el-button type="primary" style="width: 100%;" @click="submitClick">登  录</el-button>
        </el-form-item>
      </el-form>
</div>
</template>

<script>
 import axios from 'axios';
  export default{
    data(){
    return {

      checked: true,
      loginForm: {
        username: '',
        password: ''
      },
      loading: false
    }
    }
    ,methods:{
      submitClick:function(){
      console.log(this.loginForm)
      var self=this
      axios.get("http:localhost:8086/user/login",{params:{
        name:this.loginForm.username,
        pwd:this.loginForm.password
      }})
      .then(function(d){
      /*  console.log(d)
        if(d.data==''){
          self.$message('用户名密码错误')
          return
        } */
        console.log("---------");
          self.$store.commit('user', d.data);
           var rids='';
           d.data.roles.forEach(function(item){
             rids+=item.rid+',';
           })
           console.log(rids)
            console.log('角色id：');
            console.log(1)
            console.log("store储存user信息：",self.$store.state.user);

             console.log(2);
                      axios.get('http:localhost:8086/menu/all',{params:{rid :rids}})
                      .then(resp2=> {
                       self.$store.commit('menu', resp2.data);

                       console.log(resp2);
                       console.log("store储存menu信息：",self.$store.state.menu);
                     self.$router.push({path:'/'})
  })
    /*  self.user=d.data
    /*  window.location.href='http://localhost:8082/#/main?'+self.user
      let s=JSON.stringify(self.user)
      self.$router.push({path:'/',query:{user:s}}) */


      .catch(function(v){

        console.log(v)
      })
      }).catch(r=>{
        this.$message("登陆失败")

      })
    }
  },
  }
</script>

<style scoped="scoped">
  .login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 40px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }

  .login_title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }
  .login_remember {
    margin: 0px 0px 35px 0px;
    text-align: left;
  }

  .el-button--primary{
  	background-color: #34485D;
  	border-color: #34485D;
  }
</style>
